package nk;

import java.util.Locale;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Ab32 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();
        PriorityQueue<Long> pq = new PriorityQueue<>();

        for (int i = 0; i < n; i++) {
            pq.offer(scanner.nextLong());
        }
        long ans = 0;
        while (pq.size() > 1) {
            Long a = pq.poll();
            Long b = pq.poll();
            ans += a + b;
            pq.offer(a + b);
        }
        System.out.println(ans);
    }


}
